/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.webservices;

import cs575.coresystem.Facade;
import cs575.coresystem.Utils;
import cs575.dbentities.Session;
import cs575.dbentities.GroupEx;
import cs575.dbentities.Task;
import cs575.dbentities.User;
import cs575.dbentities.Converter;
import cs575.dbentities.GroupEx;
import cs575.dbentities.GroupInvitation;
import cs575.dbentities.GroupMember;
import cs575.dbentities.TaskUser;
import java.util.List;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

/**
 *
 * @author bms
 */
@WebService(serviceName = "WiDo")
public class WiDo {

    private Facade f = new Facade();

    // <editor-fold defaultstate="collapsed" desc="Authentication-methods">
    
    @WebMethod(operationName = "login")
    public Session login(@WebParam(name = "username") String username, @WebParam(name = "password") String password) {
        //System.out.print("login argument " + " username = " + username + "password = " + password);
        Session s = f.login(username, password); 
        //System.out.println("Result = " + ((s == null)? "null" : s.getSessionKey()));
        return s;
    }

    @WebMethod(operationName = "logout")
    public Boolean logout(@WebParam(name = "session") Session session) {
        return f.logout(session);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="User-methods">
    
    // The only method that it will build successfully
    @WebMethod(operationName = "createUser")
    public Boolean createUser(@WebParam(name = "userName") String userName, @WebParam(name = "email") String email, @WebParam(name = "password") String password) {
        return f.createUser(userName, email, password);
    }
    
    @WebMethod(operationName = "editUser")
    public Boolean editUser(@WebParam(name = "session") Session session, @WebParam(name = "userId") int userId, @WebParam(name = "userName") String userName, @WebParam(name = "email") String email, @WebParam(name = "password") String password) {
        return f.editUser(session, userId, userName, email, password);
    }

    @WebMethod(operationName = "removeUser")
    public Boolean removeUser(@WebParam(name = "session") Session session, @WebParam(name = "userId") int userId) {
        return f.removeUser(userId);
    }

    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Group-methods">
    
    @WebMethod(operationName = "createGroup")
    public Boolean createGroup(@WebParam(name = "session") Session session, @WebParam(name = "groupName") String groupName, @WebParam(name = "groupDescription") String groupDescription) {
        return f.createGroup(session, groupName, groupDescription);
    }

    @WebMethod(operationName = "editGroup")
    public Boolean editGroup(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId, @WebParam(name = "groupName") String groupName, @WebParam(name = "groupDescription") String groupDescription) {
        return f.editGroup(session, groupId, groupName, groupDescription);
    }

    @WebMethod(operationName = "inviteUserToGroup")
    public Boolean inviteUserToGroup(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId, @WebParam(name = "userUserId") int destUserId, @WebParam(name = "roleId") int roleId, @WebParam(name = "comment") String comment) {
        return f.inviteUserToGroup(session, groupId, destUserId, roleId, comment);
    }
    
    @WebMethod(operationName = "setUserRole")
    public Boolean setUserRole(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId, @WebParam(name = "userUserId") int destUserId, @WebParam(name = "roleId") int roleId) {
        return f.setUserRole(session, groupId, destUserId, roleId);
    }
    
    @WebMethod(operationName = "getGroupInfo")
    public GroupEx getGroupInfo(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId) {
        return f.getGroupInfo(session, groupId);
    }

    // TODO: Bander, fix these
    @WebMethod(operationName = "getGroups")
    public List<GroupMember> getGroups(@WebParam(name = "session") Session session, @WebParam(name = "sourceUserId") int sourceUserId) {
        return f.getGroups(session, sourceUserId);
    }
    
    @WebMethod(operationName = "getTasks")
    public List<Task> getTasks(Session session) {
        return f.getTasks(session);
    }
    
    
    @WebMethod(operationName = "getPendingTasks")
    public List<Task> getPendingTasks(Session session) {
        return f.getPendingTasks(session);
    }
    
    @WebMethod(operationName = "getCompletedTasks")
    public List<Task> getCompletedTasks(Session session) {
        return f.getCompletedTasks(session);
    }  
        // TODO: Bander, fix these
    @WebMethod(operationName = "getGroupTasks")
    public List<Task> getGroupTasks(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId) {
        return f.getGroupTasks(session,groupId);
    }

    @WebMethod(operationName = "getGroupMembers")
    public List<GroupMember> getGroupMembers(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId) {
        return f.getGroupMembers(session,groupId);
    }

    @WebMethod(operationName = "acceptGroupInvitation")
    public Boolean acceptGroupInvitation(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId, @WebParam(name = "userId") int userId) {
       return f.acceptGroupInvitation(session, groupId, userId);
    }

    @WebMethod(operationName = "rejectGroupInvitation")
    public Boolean rejectGroupInvitation(@WebParam(name = "session") Session session, @WebParam(name = "groupId") int groupId, @WebParam(name = "userId") int userId) {
       return f.rejectGroupInvitation(session, groupId, userId);
    }

    // TODO: Bander, fix this
    @WebMethod(operationName = "getGroupsInvitation")
    public List<GroupInvitation> getGroupsInvitation(@WebParam(name = "session") Session session, @WebParam(name = "userId") int userId) {
        return f.getGroupsInvitation(session, userId);
    }

    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Task-methods">
    
    @WebMethod(operationName = "createTask")
    public Task createTask(@WebParam(name = "session") Session session, @WebParam(name = "taskName") String taskName, @WebParam(name = "taskDescription") String taskDescription, @WebParam(name = "dueDate") String dueDate, @WebParam(name = "groupId") int groupId) {
       return f.createTask(session, taskName, taskDescription, dueDate, groupId);
    }   
    
    @WebMethod(operationName = "createPrivateTask")
    public Task createPrivateTask(@WebParam(name = "session") Session session, @WebParam(name = "taskName") String taskName, @WebParam(name = "taskDescription") String taskDescription, @WebParam(name = "dueDate") String dueDate) {
       return f.createTask(session, taskName, taskDescription, dueDate);
    }  
    
    @WebMethod(operationName = "editTask")
    public Boolean editTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId, @WebParam(name = "taskName") String taskName, @WebParam(name = "taskDescription") String taskDesc, @WebParam(name = "dueDate") String dueDate, @WebParam(name = "status") int status) {
       return f.editTask(session, taskId, taskName, taskDesc, dueDate, status);
    }
    
    @WebMethod(operationName = "removeTask")
    public Boolean removeTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId) {
       return f.removeTask(session, taskId);
    }
    
    @WebMethod(operationName = "assignTask")
    public Boolean assignTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId, @WebParam(name = "destUserId") int destUserId) {
       return f.assignTask(session, taskId, destUserId);
    }
    
    @WebMethod(operationName = "completeTask")
    public Boolean completeTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId) {
       return f.completeTask(session, taskId);
    }   
    
    @WebMethod(operationName = "acceptTask")
    public Boolean acceptTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId){
       return f.acceptTask(session, taskId);
    } 
    
    @WebMethod(operationName = "rejectTask")
    public Boolean rejectTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId){
       return f.rejectTask(session, taskId);
    }   
     
    @WebMethod(operationName = "getTask")
    public Task getTask(@WebParam(name = "session") Session session, @WebParam(name = "taskId") int taskId){
       return f.getTask(session, taskId);
    }      
   
    // </editor-fold>

}
